Ensure parent directory exists before writing a file#2823
Closed
Ensure parent directory exists before writing a file#2823
Conversation
e-nomem
commented
Nov 4, 2025
| assert_snapshot!(writer.directories.iter().sorted().join("\n"), @r" | ||
| hello_world-0.1.0.dist-info | ||
| hello_world-0.1.0.dist-info/licenses | ||
| hello_world-0.1.0.dist-info/licenses/licenses |
Contributor
Author
There was a problem hiding this comment.
This extra level of licenses nesting being missing from the previous snapshot output is the exact issue I had
6839676 to
f597688
Compare
f597688 to
e792af1
Compare
messense
pushed a commit
that referenced
this pull request
Nov 6, 2025
In #2823 I considered the idea of removing `add_directory()` entirely from the `ModuleWriter` trait since it seemed error-prone to require the programmer to ensure it was called everywhere. I decided to make a PR for that as well to see what it would look like.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I ran into a bug when I moved my
LICENSEfile from the root of the repository toLICENSES/MIT.txtand updated thelicense-filedirective in mypyproject.tomlto match.uv build --sdist .anduv build --wheel .both had no issues, but runninguv lock -Ureported an error.I tracked the issue down to the fact that both
WheelWriterandSdistWriterdon't care about adding directories and just stub out their implementation ofadd_directory(), butPathWriterdoes, and it needs the parent directory to exist before the file is written.In this PR I ensured that all non-test code that calls
add_bytes_with_permissions()callsadd_directory()first. I considered givingadd_bytes_with_permissions()a default impl that callsadd_directory()and adding a layer of indirection to the trait but decided against it.Alternately, given that 2 of the 3 main implementations of
ModuleWriterdon't care about directories, maybeadd_directory()shouldn't be part of the trait and should be an internal implementation detail for thePathWriterimplementation ofadd_bytes_with_permissions()? (See #2824 for a take at this)